﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using XinGuanERP.Attributes.system;
using XinGuanERP.Models.Vo.system;
using XinGuanERP.Services;
using XinGuanERP.Services.system.IServices;
using XinGuanERP.Utils;

namespace XinGuanERP.Controllers.system
{
    [DynamicApiController]
    public class SysMenuController
    {
        private readonly ISysMenuService _sysMenuService;
        public SysMenuController(ISysMenuService sysMenuService)
        {
            _sysMenuService = sysMenuService;
        }
        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil PostSysMenu(SysMenuVo sysMenuVo) =>
             ResultUtil.ok(_sysMenuService.UpdateSysMenu(sysMenuVo));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetSysMenuWithTree() =>
            ResultUtil.ok(_sysMenuService.GetSysMenuWithTree());

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil DeleteSysMenu(string id) =>
            ResultUtil.ok(_sysMenuService.DeleteSysMenu(id));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetSysMenuWithPage(int page, int pageSize, string? menuName, string? parentId)
            => ResultUtil.ok(_sysMenuService.GetSysMenuWithPage(page, pageSize, menuName, parentId));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetSysMenu(string id)
            => ResultUtil.ok(_sysMenuService.GetSysMenuById(id));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetSysMenuAndExcludeNodeWithOptionTree(string? nodeId)
            => ResultUtil.ok(_sysMenuService.GetSysMenuAndExcludeNodeWithOptionTree(nodeId));

        [Authorize]
        [ServiceFilter(typeof(MyActionFilterAttribute))]
        public ResultUtil GetGrantMenuWithList()
            => ResultUtil.ok(_sysMenuService.GetGrantMenuWithList());
    }
}
